import QtQuick
import QtQuick.Layouts
import QtQuick.Controls.Material
import Qt5Compat.GraphicalEffects


Item {
    id: usbProcessBack
    width: rootWidth
    height: rootHeight /*- 150*/

    property bool completionDialogShown: false
    property bool autoWrapEnabled: false  // 自动换行功能开关状态

    // 计数相关变量
    property bool plc_M61: Cpp_PLC.NetWork_M61      //工进动作
    property bool plc_M96: Cpp_PLC.NetWork_M96      // 超长加工
    property bool plc_M97: Cpp_PLC.NetWork_M97      // 超短加工
    property bool plc_X_13: Cpp_PLC.IO_X13          // 锯片后位

    Component.onCompleted: {
        Cpp_PLC.QML_CurrentPage = 17;
        Cpp_PLC.write_Modbus_RTU_Hold_16(48,"3")
        Cpp_PLC.write_Modbus_RTU_Coils(142,"1")
        // Cpp_PLC.write_Modbus_RTU_Hold_16(231,"0")
    }

    A_NumberKeyboard{
        id: usbProcessKeyboard
        isDirectOverwrite: false
    }

    Item{
        anchors.top: usbProcessBack.top
        anchors.horizontalCenter: usbProcessBack.horizontalCenter
        width: 1080
        height: 1585

        // // 表格背景
        // Rectangle{
        //     anchors.fill: parent
        //     border.width: 1
        // }

        // 表格标题栏（适配usbCutDataModel字段）
        Row {
            id: headerRow
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            height: 60
            z:10

            Rectangle {width: 70;height: parent.height;border.color: "#cccccc";
                Text {anchors.centerIn: parent;font.bold: true;font.pixelSize: 15;
                    text: qsTr("序 号"); } }
            Rectangle { width: 120; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("材料名称") } }
            Rectangle { width: 95; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("颜色") } }
            Rectangle { width: 75; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("ID") } }
            Rectangle { width: 120; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("规格型号") } }
            Rectangle { width: 80; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("切割长度") } }
            Rectangle { width: 80; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("左角度") } }
            Rectangle { width: 80; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("右角度") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("原料长度") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("剩余长度") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("总数量") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("已加工") } }
        }

        // 表格项目
        ListView {
            id: materialListView
            anchors.top: headerRow.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            height: 1220
            model: usbCutDataModel  // 绑定usbCutDataModel单例
            spacing: 1
            clip: true
            boundsBehavior: Flickable.StopAtBounds

            Connections {
                target: usbCutDataModel
                function onModelDataUpdated() {  // 适配usbCutDataModel的数据更新信号
                    if (Cpp_PLC.NetWork_CurrentIndex >= usbCutDataModel.rowCount()) {
                        Cpp_PLC.NetWork_CurrentIndex = -1;
                    }
                    materialListView.currentIndex = -1;
                    console.log("材料模型数据更新，重置currentIndex");
                }
            }

            // 检查当前行是否完成（总数量=已加工数量）
            function checkComplete(rowIndex) {
                if (rowIndex < 0 || rowIndex >= usbCutDataModel.rowCount()) return false;
                const item = usbCutDataModel.get(rowIndex);  // 调用usbCutDataModel的get方法
                return item.totalCount === item.processedCount && item.totalCount !== 0;
            }

            // 查找下一个未完成的行
            function findNextValidRow(startIndex) {
                for (let i = startIndex + 1; i < usbCutDataModel.rowCount(); i++) {
                    if (!checkComplete(i)) {
                        return i;
                    }
                }
                return -1;
            }

            // 自动移动到下一个有效行
            function moveToNextValidRow(currentIndex) {
                const nextIndex = findNextValidRow(currentIndex);
                if (nextIndex !== -1) {
                    materialListView.currentIndex = nextIndex;
                    console.log("自动跳过已完成行，移动到第" + (nextIndex + 1) + "行");
                } else {
                    materialListView.currentIndex = -1;
                    console.log("后续无有效行，取消选中");
                    checkAndShowCompletionDialog();
                }
            }

            // 检查所有行是否都已完成
            function checkAllComplete() {
                const model = usbCutDataModel;
                if (model.rowCount() === 0) return false;
                for (let i = 0; i < model.rowCount(); i++) {
                    if (!checkComplete(i)) {
                        return false;
                    }
                }
                return true;
            }

            // 检查并显示完成弹窗
            function checkAndShowCompletionDialog() {
                if (checkAllComplete() && !completionDialogShown) {
                    completionDialog.visible = true;
                    completionDialogShown = true;
                }
            }

            onCurrentIndexChanged: {
                if (currentIndex >= 0 && currentIndex < usbCutDataModel.rowCount()) {
                    const currentItem = usbCutDataModel.get(currentIndex);
                    console.log("ListView换行，当前选中第" + (currentIndex + 1) + "行，执行PLC写入指令");

                    // 适配usbCutDataModel的属性（切割长度、角度等）
                    console.log("写入 切割长度: "+currentItem.cuttingLength + " 左角度: "+currentItem.leftAngle +
                                " 右角度: "+currentItem.rightAngle +" 总数量: "+currentItem.totalCount)
                }
            }

                    // // 切割长度处理（根据实际业务调整）
                    // if(Number(currentItem.cuttingLength) < Number(Cpp_PLC.ExtraShort_MaterialLengthMin)) {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_32(1440, currentItem.cuttingLength)
                    // } else if(Number(currentItem.cuttingLength) > Number(Cpp_PLC.ExtraLong_MaterialLengthMax)) {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_32(1440, currentItem.cuttingLength)
                    // } else {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_32(1440, currentItem.cuttingLength)
                    // }

                    // // 左角度处理（根据实际业务调整）
                    // if(currentItem.leftAngle === "45") {  // usbCutDataModel中角度为QString类型
                    //     Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"1");
                    // } else if(currentItem.leftAngle === "90") {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"0");
                    // }

                    // // 右角度处理（根据实际业务调整）
                    // if(currentItem.rightAngle === "45") {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"1");
                    // } else if(currentItem.rightAngle === "90") {
                    //     Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"0");
                    // }

                    // // 总数量写入
                    // Cpp_PLC.write_Modbus_RTU_Hold_16(1480, currentItem.totalCount)

                    // // 其他PLC控制指令（保持原有逻辑）
                    // Cpp_PLC.write_Modbus_RTU_Hold_16(76,"1")
                    // if(Cpp_PLC.MechineChangeAngleMode) {
                    //     Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                    //     Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                    // } else {
                    //     Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                    //     Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                    //     Cpp_PLC.write_Modbus_RTU_Coils(140,0)
                    //     Cpp_PLC.write_Modbus_RTU_Coils(141,0)
                    // }

            //     } else {
            //         console.log("无有效选中项，不执行PLC写入");
            //     }
            // }

            delegate: Item {
                width: materialListView.width
                height: 60
                // 绑定usbCutDataModel的属性
                property int currentProcessedCount: processedCount
                property int currentTotalCount: totalCount
                property int currentIndex: index

                // 监听已加工数量变化
                onCurrentProcessedCountChanged: {
                    checkCompletion();
                }

                // 监听总数量变化
                onCurrentTotalCountChanged: {
                    checkCompletion();
                }

                // 检查完成逻辑
                function checkCompletion() {
                    if (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) {
                        console.log("第" + (currentIndex + 1) + "行已完成");
                        if (materialListView.currentIndex === currentIndex) {
                            if (autoWrapEnabled) {  // 假设存在自动换行开关
                                materialListView.moveToNextValidRow(currentIndex);
                            } else {
                                console.log("自动换行已禁用，保持当前选中状态");
                            }
                        }
                        materialListView.checkAndShowCompletionDialog();
                    }
                }

                Row {
                    id: dataRow
                    height: parent.height

                    // 序号列
                    Rectangle {
                        width: 70
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                            : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: (currentIndex + 1)
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 材料名称列
                    Rectangle {
                        width: 120
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: materialName
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 颜色列
                    Rectangle {
                        width: 95
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: material_Color
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 材料ID列
                    Rectangle {
                        width: 75
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: material_ID
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 规格型号列
                    Rectangle {
                        width: 120
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: specification
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 切割长度列
                    Rectangle {
                        width: 80
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: cuttingLength
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 左角度列
                    Rectangle {
                        width: 80
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: leftAngle + "°"
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 右角度列
                    Rectangle {
                        width: 80
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: rightAngle + "°"
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 原料长度列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: rawMaterialLength
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 剩余长度列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: remainingLength
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 总数量列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: currentTotalCount
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 已加工数量列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentTotalCount === currentProcessedCount && currentTotalCount !== 0) ? "#ffcccc"
                                                                                                        : (materialListView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: currentProcessedCount
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }

                MouseArea {
                    width: dataRow.width
                    height: dataRow.height
                    onClicked: {

                        Cpp_PLC.write_Modbus_RTU_Coils(142,"1")

                        // 已完成行不允许选中
                        if (!materialListView.checkComplete(currentIndex)) {
                            materialListView.currentIndex = currentIndex;
                            console.log("选中第" + (currentIndex + 1) + "行");
                        } else {
                            console.log("第" + (currentIndex + 1) + "行已完成，不允许选中");
                        }
                        if (currentIndex >= 0 && currentIndex < usbCutDataModel.rowCount()) {
                            const currentItem = usbCutDataModel.get(currentIndex);
                            console.log("ListView换行，当前选中第" + (currentIndex + 1) + "行，执行PLC写入指令");

                            // 适配usbCutDataModel的属性（切割长度、角度等）
                            console.log("写入 切割长度: "+currentItem.cuttingLength + " 左角度: "+currentItem.leftAngle +
                                        " 右角度: "+currentItem.rightAngle +" 总数量: "+currentItem.totalCount)


                            // 切割长度处理（根据实际业务调整）
                            if(Number(currentItem.cuttingLength) < Number(Cpp_PLC.ExtraShort_MaterialLengthMin)) {
                                Cpp_PLC.write_Modbus_RTU_Hold_32(1440, Cpp_PLC.ExtraShort_MaterialLengthMin)
                            } else if(Number(currentItem.cuttingLength) > Number(Cpp_PLC.ExtraLong_MaterialLengthMax)) {
                                Cpp_PLC.write_Modbus_RTU_Hold_32(1440, Cpp_PLC.ExtraLong_MaterialLengthMax)
                            } else {
                                Cpp_PLC.write_Modbus_RTU_Hold_32(1440, currentItem.cuttingLength)
                            }

                            // Cpp_PLC.write_Modbus_RTU_Hold_32(1440, currentItem.cuttingLength)

                            // 左角度处理（根据实际业务调整）
                            if(currentItem.leftAngle === "45") {  // usbCutDataModel中角度为QString类型
                                Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"0");
                            } else if(currentItem.leftAngle === "90") {
                                Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"1");
                            }

                            // 右角度处理（根据实际业务调整）
                            if(currentItem.rightAngle === "45") {
                                Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"0");
                            } else if(currentItem.rightAngle === "90") {
                                Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"1");
                            }

                            // 总数量写入
                            Cpp_PLC.write_Modbus_RTU_Hold_16(1480, currentItem.totalCount)
                            // 当前数量写入 D66
                            Cpp_PLC.write_Modbus_RTU_Hold_16(66,currentItem.totalCount)
                            // 当前已加工数量 写入 D231
                            Cpp_PLC.write_Modbus_RTU_Hold_16(231,currentItem.processedCount)

                            // 其他PLC控制指令（保持原有逻辑）
                            Cpp_PLC.write_Modbus_RTU_Hold_16(76,"1")
                            if(Cpp_PLC.MechineChangeAngleMode) {
                                Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                                Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                            } else {
                                Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                                Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                                Cpp_PLC.write_Modbus_RTU_Coils(140,0)
                                Cpp_PLC.write_Modbus_RTU_Coils(141,0)
                            }

                        } else {
                            console.log("无有效选中项，不执行PLC写入");
                        }
                    }
                }
            }

            // 滚动条
            ScrollBar.vertical: ScrollBar {
                policy: ScrollBar.AlwaysOn
                width: 10
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.right: parent.right
            }

            // 监听模型数据更新，重置选中状态
            Connections {
                target: usbCutDataModel
                function onModelDataUpdated() {
                    materialListView.currentIndex = -1;
                    console.log("材料模型数据已更新，取消选中状态（currentIndex = -1）");
                }
            }
        }

    }


    onPlc_X_13Changed: {
        if((plc_M96 === true && plc_X_13 === true)|| (plc_M97 === true && plc_X_13 === true))
        {
            //计数+1
            // console.log("计数加1！！！！！")
            const isComplete = materialListView.checkComplete(materialListView.currentIndex);
            if (isComplete) {
                console.log("第" + (materialListView.currentIndex + 1) + "行已完成，不更新已切数量");
                return;
            }
            usbCutDataModel.incrementWorkedCount(materialListView.currentIndex);
            var updatedItem = usbCutDataModel.get(materialListView.currentIndex);
            console.log("已更新第" + (materialListView.currentIndex + 1) + "项，已切数量：" + updatedItem.workedCount);
            // materialListView.checkAndShowCompletionDialog();
        }
        else
        {
            //不计数
            // console.log("不计数!")
            console.log("无有效选中项，不更新已切数量");
        }
    }

    onPlc_M61Changed:{
        if(plc_M61 === true)
        {
            const isComplete = materialListView.checkComplete(materialListView.currentIndex);
            if (isComplete) {
                console.log("第" + (materialListView.currentIndex + 1) + "行已完成，不更新已切数量");
                return;
            }
            usbCutDataModel.incrementWorkedCount(materialListView.currentIndex);
            var updatedItem = usbCutDataModel.get(materialListView.currentIndex);
            console.log("已更新第" + (materialListView.currentIndex + 1) + "项，已切数量：" + updatedItem.workedCount);
        }
    }





    // A_Button {
    //     contentText_Data: qsTr("解析文件")
    //     anchors.top: usbProcessBack.top
    //     anchors.topMargin: 1600
    //     anchors.left: usbProcessBack.left
    //     anchors.leftMargin: 500
    //     onButtonClicked: usbCutDataModel.parseSelectedFile()
    //     enabled: fileComboBox.currentText !== ""
    // }

    Rectangle{
        anchors.right: usbProcessBack.right
        anchors.rightMargin: 5
        anchors.top: usbProcessBack.top
        anchors.topMargin: 1285
        width: 1070
        height: 495
        border.width: 2
        color: "transparent"

        ComboBox {
            id: fileComboBox
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.left: parent.left
            anchors.leftMargin: 30
            width: 400
            height: 60
            model: usbCutDataModel.fileList
            // currentText: usbCutDataModel.currentFile
            onCurrentTextChanged:
            {
                usbCutDataModel.currentFile = currentText
                console.log("当前解析文件: " + currentText)
                usbCutDataModel.parseSelectedFile()

            }
            // onAccepted: {
            //     usbCutDataModel.parseSelectedFile()
            // }

            // 当下拉框展开时重新扫描文件
            onPressedChanged: {
                if(pressed)
                {
                    usbCutDataModel.scanFiles()
                }
            }
        }


        Rectangle{
            anchors.right: parent.right
            anchors.rightMargin: 5
            anchors.top: parent.top
            anchors.topMargin: 5
            width: 600
            height: 485
            border.width: 3
            color: "transparent"

            A_Label{
                anchors.top: parent.top
                anchors.topMargin: 10
                anchors.left: parent.left
                anchors.leftMargin: 30
                label_Data: qsTr("料高")
            }

            A_NumberInput{
                id: heightSetting_Input
                inputWidth: 300
                anchors.top: parent.top
                anchors.topMargin: 10
                anchors.left: parent.left
                anchors.leftMargin: 280
                text: Cpp_PLC.MaterialHeightValue
                visible: !Cpp_PLC.MechineChangeAngleMode
                // placeholderText: "测试"
                keyboard: usbProcessKeyboard
                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(214,value)
                }

            }

            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 10
                anchors.top: parent.top
                anchors.topMargin: 100
                buttonWidth: 200
                buttonHeight: 60
                contentText_Data: Cpp_PLC.SawsStartState ? qsTr("锯  启") : qsTr("锯  停")
                contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
                contentRectangle_BorderWidth: Cpp_PLC.SawsStartState ? 5 : 3
                contentRectangle_BorderColor: Cpp_PLC.SawsStartState ? "gold" : "black"

                onButtonPressed: {
                    // console.log("锯片按下")
                    Cpp_PLC.write_Modbus_RTU_Coils(237,"1")
                }

                onButtonReleased: {
                    // console.log("锯片松开")
                    Cpp_PLC.write_Modbus_RTU_Coils(237,"0")
                }
            }


            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 240
                anchors.top: parent.top
                anchors.topMargin: 100
                buttonWidth: 200
                buttonHeight: 60
                contentText_Data: qsTr("压  紧")
                contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
                contentRectangle_BorderWidth: Cpp_PLC.ImpactState ? 5 : 3
                contentRectangle_BorderColor: Cpp_PLC.ImpactState ? "gold" : "black"

                onButtonPressed: {
                    // console.log("压紧按下")
                    Cpp_PLC.write_Modbus_RTU_Coils(236,"1")
                }

                onButtonReleased: {
                    // console.log("压紧松开")
                    Cpp_PLC.write_Modbus_RTU_Coils(236,"0")

                }
            }

            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 240
                anchors.top: parent.top
                anchors.topMargin: 180
                buttonWidth: 200
                buttonHeight: 60
                contentText_Data: qsTr("定  位")
                contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20

                onButtonPressed: {
                    // console.log("定位按下")
                    Cpp_PLC.write_Modbus_RTU_Coils(24,"1")
                }

                onButtonReleased: {
                    // console.log("定位松开")
                    Cpp_PLC.write_Modbus_RTU_Coils(24,"0")
                }
            }

            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 240
                anchors.top: parent.top
                anchors.topMargin: 260
                buttonWidth: 200
                buttonHeight: 60
                contentText_Data: qsTr("锯  切")
                contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
                contentRectangle_BorderWidth: Cpp_PLC.SawsOutState ? 5 : 3
                contentRectangle_BorderColor: Cpp_PLC.SawsOutState ? "gold" : "black"

                onButtonPressed: {
                    // console.log("锯切按下")
                    Cpp_PLC.write_Modbus_RTU_Coils(238,"1")
                }

                onButtonReleased: {
                    // console.log("锯切松开")
                    Cpp_PLC.write_Modbus_RTU_Coils(238,"0")
                }
            }

            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 240
                anchors.top: parent.top
                anchors.topMargin: 340
                buttonWidth: 200
                buttonHeight: 60
                contentText_Data: qsTr("复  位")
                contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20

                onButtonPressed: {
                    // console.log("复位按下")
                    Cpp_PLC.write_Modbus_RTU_Coils(5,"1")
                }

                onButtonReleased: {
                    // console.log("复位松开")
                    Cpp_PLC.write_Modbus_RTU_Coils(5,"0")
                }
            }




        }





    }







}
